package cn.mystyle.service.account;

import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;

import cn.mystyle.common.constant.DefaultURI;
import cn.mystyle.common.http.ServiceClient;
import cn.mystyle.model.account.Record;
import cn.mystyle.model.user.UserInfo;

/**
 * @author clark
 * 记账类业务
 */
@Service
public class RecordService
{
    
    /**
     * 记账
     * @param sessionUser 当前登录的用户
     * @param recordParam 参数
     * @return JSONObject
     */
    public JSONObject addRecord(UserInfo sessionUser, Record recordParam)
    {
        // 设置当前用户id
        recordParam.setUserId(sessionUser.getId());
        
        String reuslt = ServiceClient.call(recordParam, DefaultURI.getRecordURIKey(DefaultURI.URI_ADD));
        return JSONObject.parseObject(reuslt);
    }
    
    /**
     * 查询账目
     * @param sessionUser 当前登录的用户
     * @param recordParam 参数
     * @return JSONObject
     */
    public JSONObject queryRecord(UserInfo sessionUser, Record recordParam)
    {
        // 设置当前用户id
        recordParam.setUserId(sessionUser.getId());
        
        String reuslt = ServiceClient.call(recordParam, DefaultURI.getRecordURIKey(DefaultURI.URI_QUERY));
        return JSONObject.parseObject(reuslt);
    }
    
    /**
     * 更新账目
     * @param sessionUser 当前登录的用户
     * @param recordParam 参数
     * @return JSONObject
     */
    public JSONObject updateRecord(UserInfo sessionUser, Record recordParam)
    {
        // 设置当前用户id
        recordParam.setUserId(sessionUser.getId());
        
        String reuslt = ServiceClient.call(recordParam, DefaultURI.getRecordURIKey(DefaultURI.URI_UPDATE));
        return JSONObject.parseObject(reuslt);
    }
    
    /**
     * 删除账目
     * @param sessionUser 当前登录的用户
     * @param recordParam 参数
     * @return JSONObject
     */
    public JSONObject delRecord(UserInfo sessionUser, Record recordParam)
    {
        // 设置当前用户id
        recordParam.setUserId(sessionUser.getId());
        
        String reuslt = ServiceClient.call(recordParam, DefaultURI.getRecordURIKey(DefaultURI.URI_DEL));
        return JSONObject.parseObject(reuslt);
    }
}
